home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Mac OS X Throbber / Source / Blenders.cp next >
Encoding:
Text File  |  2000-06-24  |  7.4 KB  |  284 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    GDeviceUtils.cp
  4. #
  5. #    by Eric Traut
  6. #
  7. ------------------------------------------------------------------------------*/
  8.  
  9. #include "GDeviceUtils.h"
  10.  
  11. #include <Memory.h>
  12. #include <LowMem.h>
  13. #include <Displays.h>
  14. #include <Traps.h>
  15.  
  16.  
  17.  
  18. /*---------------------------------------------------------------
  19.     BlendVirtualDevices
  20. ---------------------------------------------------------------*/
  21.  
  22. void
  23. SimpleBlendEffect::BlendVirtualDevices(
  24.     const GraphicSurface &    inDestSurface,
  25.     VirtualGDevice **        inVDeviceList,
  26.     UInt32                    inVDeviceCount)
  27. {
  28.     #pragma unused (inVDeviceCount)
  29.  
  30.     // The simple blend effect simply involves
  31.     // copying the pixels from the first virtual
  32.     // device to the destination surface.
  33.     UInt32                 totalRows = inDestSurface.GetHeight();
  34.     UInt32                 totalCols = inDestSurface.GetWidth();
  35.     UInt8 *             srcPtr;
  36.     UInt8 *             destPtr;
  37.     
  38.     for (UInt32 row = 0; row < totalRows; row++)
  39.     {
  40.         srcPtr = inVDeviceList[0]->GetGraphicSurface().GetPixelDataPtr() + 
  41.                 inVDeviceList[0]->GetGraphicSurface().GetRowBytes() * row;
  42.         destPtr = inDestSurface.GetPixelDataPtr() + inDestSurface.GetRowBytes() * row;
  43.         
  44.         if (((((long)srcPtr) | ((long)destPtr)) & 15) == 0) {
  45.             for (UInt32 col = 0; col < totalCols; col+=sizeof(double)/2) {
  46.                 ((double *)destPtr)[0] = ((double *)srcPtr)[0];
  47.                 ((double *)destPtr)[1] = ((double *)srcPtr)[1];
  48.                 srcPtr += 2 * sizeof(double);
  49.                 destPtr += 2 * sizeof(double);
  50.             }
  51.         } else {
  52.             for (UInt32 col = 0; col < totalCols; col+=2) {
  53.                 *(UInt32 *)destPtr = *(UInt32 *)srcPtr;
  54.                 srcPtr += 4;
  55.                 destPtr += 4;
  56.             }
  57.         }
  58.     }
  59. }
  60.  
  61.  
  62. /*---------------------------------------------------------------
  63.     DimVariably
  64. ---------------------------------------------------------------*/
  65.  
  66. UInt16 *
  67. ThrobEffect::DimVariably(
  68.     UInt16        *in,
  69.     UInt16        *out,
  70.     int            ratio,
  71.     int            count,
  72.     int            start,
  73.     int            stop)
  74. {
  75.     UInt16    *outer = out;
  76.     UInt16    *inner = in;
  77.  
  78.     int    row;
  79.  
  80.     for (row = 0; row < start && row < count; row++) {
  81.         *outer++ = *inner++;
  82.     }
  83.     for (       ; row < stop && row < count; row++) {
  84.         int            inPixel1 = *inner++;
  85.  
  86.         UInt32        red = (((inPixel1 >> 10) & 0x1f) * ratio + 31) >> 6;
  87.         UInt32        green = (((inPixel1 >> 5) & 0x1f) * ratio + 31) >> 6;
  88.         UInt32        blue = ((inPixel1 & 0x1f) * ratio + 31) >> 6;
  89.  
  90.         *outer++ = ((red) << 10) | ((green) << 5) | (blue);
  91.     }
  92.     for (       ; row < count; row++) {
  93.         *outer++ = *inner++;
  94.     }
  95.     return out;
  96. }
  97.  
  98.  
  99. /*---------------------------------------------------------------
  100.     BlendVirtualDevices
  101. ---------------------------------------------------------------*/
  102.  
  103. UInt16 Row[8192];
  104.  
  105. void
  106. ThrobEffect::BlendVirtualDevices(
  107.     const GraphicSurface &    inDestSurface,
  108.     VirtualGDevice **        inVDeviceList,
  109.     UInt32                    inVDeviceCount)
  110. {
  111.     #pragma unused (inVDeviceCount)
  112.  
  113.     // The simple blend effect simply involves
  114.     // copying the pixels from the first virtual
  115.     // device to the destination surface.
  116.     UInt32                 totalRows = inDestSurface.GetHeight();
  117.     UInt32                 totalCols = inDestSurface.GetWidth();
  118.     UInt8 *             srcPtr;
  119.     UInt8 *             destPtr;
  120.  
  121.     int        ticks = LMGetTicks();
  122.     int        dimRatio = ticks & 63;
  123.     if (ticks & 64) dimRatio = 63 - dimRatio;
  124.  
  125.     UInt16    *rowPtr = &Row[0];
  126.     
  127.     rowPtr = (UInt16 *) (-32 & (31 + (int)rowPtr));
  128.  
  129.     Rect    OKRect = *(Rect *)0x40;
  130.  
  131.     for (UInt32 row = 0; row < totalRows; row++)
  132.     {
  133.         srcPtr = inVDeviceList[0]->GetGraphicSurface().GetPixelDataPtr() + 
  134.                 inVDeviceList[0]->GetGraphicSurface().GetRowBytes() * row;
  135.         destPtr = inDestSurface.GetPixelDataPtr() + inDestSurface.GetRowBytes() * row;
  136.         
  137.         if (row >= OKRect.top && row < OKRect.bottom) {
  138.             srcPtr = (UInt8 *)DimVariably((UInt16 *)srcPtr, Row, dimRatio & (-4), totalCols, OKRect.left, OKRect.right);
  139.         }
  140.  
  141.         if (((((long)srcPtr) | ((long)destPtr)) & 15) == 0) {
  142.             for (UInt32 col = 0; col < totalCols; col+=sizeof(double)/2) {
  143.                 ((double *)destPtr)[0] = ((double *)srcPtr)[0];
  144.                 ((double *)destPtr)[1] = ((double *)srcPtr)[1];
  145.                 srcPtr += 2 * sizeof(double);
  146.                 destPtr += 2 * sizeof(double);
  147.             }
  148.         } else {
  149.             for (UInt32 col = 0; col < totalCols; col+=2) {
  150.                 *(UInt32 *)destPtr = *(UInt32 *)srcPtr;
  151.                 srcPtr += 4;
  152.                 destPtr += 4;
  153.             }
  154.         }
  155.     }
  156. }
  157.  
  158.  
  159. /*---------------------------------------------------------------
  160.     SetEffectValue
  161. ---------------------------------------------------------------*/
  162.  
  163. void
  164. DontThrobEffect::SetEffectValue(
  165.     UInt16                inValueIndex,
  166.     double                inValue)
  167. {
  168.     if (inValueIndex == 0)
  169.         mPrimaryScreenFraction = inValue;
  170. }
  171.  
  172.  
  173. /*---------------------------------------------------------------
  174.     DimVariably
  175. ---------------------------------------------------------------*/
  176.  
  177. UInt16 *
  178. DontThrobEffect::DimVariably(
  179.     UInt16        *in,
  180.     UInt16        *out,
  181.     int            ratio,
  182.     int            count,
  183.     int            start,
  184.     int            stop)
  185. {
  186.     UInt16    *outer = out;
  187.     UInt16    *inner = in;
  188.  
  189.     int    row;
  190.  
  191.     for (row = 0; row < start && row < count; row++) {
  192.         int            inPixel1 = *inner++;
  193.  
  194.         UInt32        red = (((inPixel1 >> 10) & 0x1f) * ratio + 31) >> 6;
  195.         UInt32        green = (((inPixel1 >> 5) & 0x1f) * ratio + 31) >> 6;
  196.         UInt32        blue = ((inPixel1 & 0x1f) * ratio + 31) >> 6;
  197.  
  198.         *outer++ = ((red) << 10) | ((green) << 5) | (blue);
  199.     }
  200.     if (stop != start) { *(short *)0x54 = row; *(short *)0x56 = start; *(short *)0x58 = stop; *(short *)0x5A = count; }
  201.     for (       ; row < stop && row < count; row++) {
  202.         *(long *)0x50 += 1;
  203.         *outer++ = *inner++;
  204.     }
  205.     for (       ; row < count; row++) {
  206.         int            inPixel1 = *inner++;
  207.  
  208.         UInt32        red = (((inPixel1 >> 10) & 0x1f) * ratio + 31) >> 6;
  209.         UInt32        green = (((inPixel1 >> 5) & 0x1f) * ratio + 31) >> 6;
  210.         UInt32        blue = ((inPixel1 & 0x1f) * ratio + 31) >> 6;
  211.  
  212.         *outer++ = ((red) << 10) | ((green) << 5) | (blue);
  213.     }
  214.     return out;
  215. }
  216.  
  217.  
  218. /*---------------------------------------------------------------
  219.     BlendVirtualDevices
  220. ---------------------------------------------------------------*/
  221.  
  222. void
  223. DontThrobEffect::BlendVirtualDevices(
  224.     const GraphicSurface &    inDestSurface,
  225.     VirtualGDevice **        inVDeviceList,
  226.     UInt32                    inVDeviceCount)
  227. {
  228.     #pragma unused (inVDeviceCount)
  229.  
  230.     // The simple blend effect simply involves
  231.     // copying the pixels from the first virtual
  232.     // device to the destination surface.
  233.     UInt32                 totalRows = inDestSurface.GetHeight();
  234.     UInt32                 totalCols = inDestSurface.GetWidth();
  235.     UInt8 *             srcPtr;
  236.     UInt8 *             destPtr;
  237.  
  238.     int        ticks = LMGetTicks();
  239.     int        dimRatio = ticks & 63;
  240.     if (ticks & 64) dimRatio = 63 - dimRatio;
  241.  
  242.     UInt16    *rowPtr = &Row[0];
  243.     
  244.     rowPtr = (UInt16 *) (-32 & (31 + (int)rowPtr));
  245.  
  246.     Rect    OKRect = *(Rect *)0x40;
  247.     InsetRect(&OKRect, 1, 1);
  248.     
  249.     for (UInt32 row = 0; row < totalRows; row++)
  250.     {
  251.         srcPtr = inVDeviceList[0]->GetGraphicSurface().GetPixelDataPtr() + 
  252.                 inVDeviceList[0]->GetGraphicSurface().GetRowBytes() * row;
  253.         destPtr = inDestSurface.GetPixelDataPtr() + inDestSurface.GetRowBytes() * row;
  254.         
  255.         if (OKRect.top < OKRect.bottom && OKRect.left < OKRect.right) {
  256.             if (row >= OKRect.top && row < OKRect.bottom) {
  257.                 srcPtr = (UInt8 *)DimVariably((UInt16 *)srcPtr, Row, dimRatio & (-4), totalCols, OKRect.left, OKRect.right);
  258.             } else {
  259.                 srcPtr = (UInt8 *)DimVariably((UInt16 *)srcPtr, Row, dimRatio & (-4), totalCols, 0x7FFF, 0x7FFF);
  260.             }
  261.         }
  262.         
  263.         if (((((long)srcPtr) | ((long)destPtr)) & 15) == 0) {
  264.             for (UInt32 col = 0; col < totalCols; col+=sizeof(double)/2) {
  265.                 ((double *)destPtr)[0] = ((double *)srcPtr)[0];
  266.                 ((double *)destPtr)[1] = ((double *)srcPtr)[1];
  267.                 srcPtr += 2 * sizeof(double);
  268.                 destPtr += 2 * sizeof(double);
  269.             }
  270.         } else {
  271.             for (UInt32 col = 0; col < totalCols; col+=2) {
  272.                 *(UInt32 *)destPtr = *(UInt32 *)srcPtr;
  273.                 srcPtr += 4;
  274.                 destPtr += 4;
  275.             }
  276.         }
  277.     }
  278. }
  279.  
  280.  
  281.  
  282.  
  283.  
  284.